package com.ithuameng.admin.config;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StringDeserializer;
import org.springframework.boot.jackson.JsonComponent;

import java.io.IOException;

/**
 * String 去除左右空格
 *
 * @author ithuameng
 */
@JsonComponent
public class TrimStringDeserializer extends StringDeserializer {

    private static final long serialVersionUID = -3964860943869784604L;

    @Override
    public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        String text = super.deserialize(p, ctxt);
        return text != null ? text.trim() : null;
    }
}
